package com.qingke.easyjava.jdbc.command.impl;

import java.util.List;

import com.qingke.easyjava.jdbc.app.BeSuperDao;
import com.qingke.easyjava.jdbc.command.PlayerCommand;
import com.qingke.easyjava.jdbc.pojo.Player;
import com.qingke.easyjava.jdbc.pojo.Question;
import com.qingke.easyjava.jdbc.util.QingkeConsole;

public class AskCommand extends PlayerCommand {

	public AskCommand(Player playerProfile) {
		super(playerProfile);
	}

	@Override
	public void execute() {
		String content = QingkeConsole.askUserInput("Please enter a question");
		int credit = QingkeConsole.askUserInputInt("Please enter the credit");
		
		int score = playerProfile.getScore();
		if(score < credit) {
			QingkeConsole.println("Insufficient credit! You have only" + score + "credit(s)");
			credit = score;
		}
		Question question = new Question(-1,content,playerProfile,credit);
		BeSuperDao dao = new BeSuperDao();
		dao.upsertQuestion(question);
		
		List<Question> qList =dao.getQuestionFrom(playerProfile);
		playerProfile.setQuestions(qList);
		
		QingkeConsole.println("Your question has been recorded");
	}

}
